#ifndef ROBOTJSONI_H
#define ROBOTJSONI_H

#include "RobotDef.h"
#include <QtCore>

class TmJsonEngineThread;

class TmJsonEngineAuto : public QThread{
public:
    TmJsonEngineAuto(TmJsonEngineThread* pThread);
    void StartAuto();
    void StopAuto();

private:
    TmJsonEngineThread* m_pThread;
    bool m_bStart;

    // QThread interface
protected:
    void run();
};

class TmJsonEngineThread : public QThread{
public:
    TmJsonEngineThread();
    void setExit();

    bool Load(QString strPath);
    void CallByName(QString strName);
    void CallByClass(QString strClassName);
    void CallByContent(QByteArray strArray);
    void Stop();
    bool IsPlaying();
    void AutoPlay();
    void List(QStringList &strList);

    void _tm_auto_play();

    bool m_bExit;
private:
    QString m_strJsonPath;
    int m_nFrameIndex;
    bool m_bFrameLoad;
    QMap<QString, QJsonArray> m_jsonActionsMap;
    QMap<QString, QStringList> m_jsonClassMap;
    QMap<int, QJsonObject> m_jsonCmdMap;

    QList<QJsonArray> m_jsonAutoAction; // auto_action list
    void _load_auto_action(QString strFilePath);

    TmJsonEngineAuto* m_pJsonAuto;
    // QThread interface
protected:
    void run();
};

class RobotJsonI : public Robot::Json
{
public:
    RobotJsonI();

    // Json interface
public:
    bool Load(const std::string &strPath, const Ice::Current &);
    void CallByName(const std::string &strName, const Ice::Current &);
    void CallByClass(const std::string &strClassName, const Ice::Current &);
    void CallByContent(const std::string &strArray, const Ice::Current &);
    void Stop(const Ice::Current &);
    bool IsPlaying(const Ice::Current &);
    void AutoPlay(const Ice::Current &);
    void List(Ice::StringSeq &strList, const Ice::Current &);
};

#endif // ROBOTJSONI_H
